package com.baymax.test.scene.demo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.Toast
import com.baymax.test.scene.BaseScene
import com.baymax.test.scene.addButton
import com.baymax.test.scene.addDFView
import com.baymax.test.scene.newFlexContainer
import com.baymax.test.scene.newSceneFlexContainer
import com.baymax.test.scene.replace.ReplaceManager.replace
import com.billy.cc.core.component.CC
import com.bytedance.scene.Scene
import com.bytedance.scene.group.GroupScene
import com.bytedance.scene.ktx.replace
import com.bytedance.scene.ktx.requireNavigationScene
import com.google.common.util.concurrent.ListenableFuture

class PluginTestScene : GroupScene() {
    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): ViewGroup {
        return p1.newFlexContainer(attachParent = false) {
            val frId = View.generateViewId()
            addDFView(-1, -2, FrameLayout(requireActivity())) {
                id = frId
                minimumHeight = 100
            }
            replace(frId, PluginScene(), "head")
            addButton("load scene from plugin") {
                CC.obtainBuilder("view")
                    .setActionName("scene")
                    .build()
                    .call()
                    .getDataItemWithNoKey<Scene?>()?.let {
                        replace(frId, it, "head")
                    } ?: println("not find")

            }

            addButton("load scene from plugin and push") {
                CC.obtainBuilder("view")
                    .setActionName("scene")
                    .build()
                    .call()
                    .getDataItemWithNoKey<Scene?>()?.let {
                        requireNavigationScene().push(it)
                    } ?: println("not find")

            }

            addButton("assets methods") {
                val declaredMethods = resources.assets.javaClass.declaredMethods
                println(declaredMethods.joinToString { it.name })
            }




        }
    }

    class PluginScene : Scene() {
        override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): View {
            return p1.newSceneFlexContainer {
                addButton("plugin from host") {
                    Toast.makeText(requireActivity(), "plugin from host", Toast.LENGTH_SHORT).show()
                }
            }
        }

    }
}